package com.common.ui.views.loading;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;

import com.common.R;

/**
 * [description about this class]
 * 加载数据页面
 * @author jack
 */

public class LoadingView extends FrameLayout {

    private RelativeLayout rlLoading;//正在加载页面
    private RelativeLayout rlNoNet;//没有网络页面
    private RelativeLayout rlError;//加载失败页面
    private RelativeLayout rlNoData;//加载失败页面
    private Context context;

    public LoadingView(Context context) {
        super(context);
        this.context = context;
        init();
    }

    public LoadingView(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context = context;
        init();
    }

    public LoadingView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.context = context;
        init();
    }

    private void init() {

        View inflate = LayoutInflater.from(context).inflate(R.layout.loading, null);
        rlLoading = (RelativeLayout) inflate.findViewById(R.id.rl_loading);
        rlNoNet = (RelativeLayout) inflate.findViewById(R.id.rl_no_net);
        rlError = (RelativeLayout) inflate.findViewById(R.id.rl_error);
        rlNoData = (RelativeLayout) inflate.findViewById(R.id.rl_no_data);

        rlNoNet.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
            }
        });

        rlError.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
            }
        });

        rlNoData.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
            }
        });

        addView(inflate);
    }

    public void showLoading(){
        rlLoading.setVisibility(View.VISIBLE);
        rlNoNet.setVisibility(View.GONE);
        rlError.setVisibility(View.GONE);
        rlNoData.setVisibility(View.GONE);
    }

    public void showNoNet(){
        rlLoading.setVisibility(View.GONE);
        rlNoNet.setVisibility(View.VISIBLE);
        rlError.setVisibility(View.GONE);
        rlNoData.setVisibility(View.GONE);
    }

    public void showError(){
        rlLoading.setVisibility(View.GONE);
        rlNoNet.setVisibility(View.GONE);
        rlError.setVisibility(View.VISIBLE);
        rlNoData.setVisibility(View.GONE);
    }

    public void showNoData(){
        rlLoading.setVisibility(View.GONE);
        rlNoNet.setVisibility(View.GONE);
        rlError.setVisibility(View.GONE);
        rlNoData.setVisibility(View.VISIBLE);
    }

    public void hide(){
        setVisibility(View.GONE);
    }

}
